Chris Pollett > Old Classes >
CS174

( Print View )

Student Corner:
  [Grades Sec1]
  [Grades Sec2]

  [Submit Sec1]
  [Submit Sec2]

  [Class Sign Up Sec1]
  [Class Sign Up Sec2]

  [
Lecture Notes]
  [Discussion Board]

Course Info:
  [Texts & Links]
  [Topics/Outcomes]
  [Outcomes Matrix]
  [Grading]
  [HW Info]
  [Exam Info]
  [Regrades]
  [Honesty]
  [Additional Policies]
  [Announcements]

HW Assignments:
  [Hw1]  [Hw2]  [Hw3]
  [Hw4]  [Hw5]  [Hw6]

Practice Exams:
  [Mid1]  [Final]

                           












HW#2 --- last modified February 28 2019 22:28:28..

Solution set.

Due date: Sep 29

Files to be submitted:
  Hw2.zip

Purpose: To develop our first PHP project using a model view controller pattern.

Related Course Outcomes:

The main course outcomes covered by this assignment are:

(1) [Write HTML documents containing standard HTML elements including forms, tables, client-side scripts, and server-side scripts.]

(3) [Write server-side scripts that process HTML forms.]

Specification:

For this homework, you will create a small web-site for people to create one-off surveys. There will be three basic use-cases for your survey-maker. (1) Someone comes to the web-site and wants to quickly create a new survey. After storing the survey information, the person gets two urls they can publish: (a) the url where people can take the survey and (b) the url where the survey results are viewable. (2) Someone comes to the page for (a), takes the survey, then gets told thank you, and gets taken to the survey results page. (3) Someone directly goes to the page (b), in which case there is no need to say thank you.

Your program will be run by unzipping your Hw2.zip in the document root of the grader's installation of XAMPP. It will be tested by going to the page http://localhost/Hw2/ . To take an existing survey, the grader will go to a url of the form:

http://localhost/Hw2/index.php?action=takesurvey&num=somesurvey_number

To see the results of an existing survey, the grader will go to a url of the form:

http://localhost/Hw2/index.php?action=surveyresults&num=somesurvey_number

The form that is used to create the survey should also have as its action "index.php" and it should use get as its method. There should be a hidden variable on the form with name action and value createsurvey. So any interaction with your web-site goes through the index.php page. i.e., this page will act as the controller in the model-view-controller (MVC) pattern. For each value of the $_GET['action'] mentioned above, you should have a function in index.php to handle the corresponding activity. At the start of your index.php you should check that if the $_GET['action'] variable is defined it is one of the values we have mentioned, if not, your program should exit with an error message. If the action is allowable, then your program should include the file "model/".$_GET['action'].php . This file should have functions useful for the file io for that action. This file serves as the model in the model view controller pattern. For instance, if the action is takesurvey, the functions useful for reading in the information about the survey items into arrays might be in the file model/takesurvey.php . To promote code re-use, takesurvey.php might further include another file which has common functions between different such models. The function in index.php which is supposed to handle takesurvey requests calls appropriate functions that were defined in takesurvey.html to get arrays of survey data set up. It might also set up additional variables. A similar thing would occur if the action was something else. As a final act in performing an action, the function then includes a view html file from the view subfolder to actually render the html that appears on the screen. This rendering should involve minimal PHP code -- mainly, it should involve echoing data that was already set up by the controller.

This completes the description of the overall code structure of your program; however, it is useful to fix a few things about creating, taking, and displaying surveys. The kind of surveys that your site needs to handle consist of line items of form:

Description of line item. [ ]

Here [] can hold a number from 1 to 10. i.e., what the person thought of that item on a scale from 1 to 10. If someone submits data to your survey it should be checked that each value submitted was 1 to 10 before changing any info in a file that might affect the survey statistics page. The survey statistics page just needs to display each of the line items and its current average value. The create survey page might look something like:

Survey Creator

Enter the descriptions of the line items for your survey
(Only the non-blank rows will be used for the survey):
1. [               ]
2. [               ]
...
10.[               ] [Add 10 more line items]
[Create survey]

Clicking the [Create survey] button should store the survey in a flat file in the model subfolder and should perform the rest of use-case (1) mentioned above. The [Add 10 more line items] button doesn't store anything into a file yet, but would create blank text fields 11 though 20 where additional items could be entered. It should also not destroy any of the data that has already been entered.

Point Breakdown

All pages in your site validate as XHTML 1.1 1pt
All three use cases basically work as described (1pt each) 3pts
Urls used for your site match the description above 1pt
Model-view-controller implemented as described above (1pt for each of M V and C) 3pts
You have an external CSS for your site that does something nontrivial and aesthetic. 1pt
You use server-side includes for something on your web-site (so can claim to have experimented with them) 1pt
Total10pts